/*
 * Copyright 2013, NuzoweR@Schneefeuer <nuzower@gmail.com>.
 * The Settlers Online - Combat Simulator (tsosim).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "Debug.h"

static debug::DebugLevel s_level = debug::DL_WARNING;

bool debug::SetLevel(std::string const& debug)
{
	if     (debug == "DEBUG"  ) SetLevel(debug::DL_DEBUG);
	else if(debug == "INFO"   ) SetLevel(debug::DL_INFO);
	else if(debug == "WARNING") SetLevel(debug::DL_WARNING);
	else if(debug == "ERROR"  ) SetLevel(debug::DL_ERROR);
	else {
		return false;
	}
	return true;
}

void debug::SetLevel(DebugLevel dl)
{
	if(dl >= DL_DEBUG && dl <= DL_ERROR)
		s_level = dl;
}

debug::DebugLevel debug::GetLevel()
{
	return s_level;
}

bool debug::CheckLevel(DebugLevel dl)
{
	return dl >= s_level;
}

// //////////////////////////////////////////////// //

std::ostream& debug::ERROR(std::ostream& out, int line, std::string const& message)
{
	if(CheckLevel(DL_ERROR))
		out << "ERROR [line:" << line << "] : " << message << std::endl;
	return out;
}

std::ostream& debug::WARNING(std::ostream& out, int line, std::string const& message)
{
	if(CheckLevel(DL_WARNING))
		out << "WARNING [line:" << line << "] : " << message << std::endl;
	return out;
}

std::ostream& debug::INFO(std::ostream& out, int line, std::string const& message)
{
	if(CheckLevel(DL_INFO))
		out << "INFO [" << line << "] : " << message << std::endl;
	return out;
}

std::ostream& debug::DEBUG(std::ostream& out, int line, std::string const& message)
{
	if(CheckLevel(DL_DEBUG))
		out << "DEBUG [" << line << "] : " << message << std::endl;
	return out;
}




